﻿Imports System.Data.OleDb
Partial Public Class Manage
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Finding the control which is causing the postback
        If IsPostBack Then


            Dim ctrlname As String = Page.Request.Params.Get("__EVENTTARGET")
            'Label1.Text = ctrlname
            If ctrlname = "ctl00$ContentPlaceHolder1$gvUserName" Then
                If (Not ClientScript.IsStartupScriptRegistered("alert")) Then
                    Page.ClientScript.RegisterStartupScript _
                    (Me.GetType(), "alert", "ToggleDiv('first');", True)
                End If
            ElseIf ctrlname = "ctl00$ContentPlaceHolder1$gvArticles" Then
                If (Not ClientScript.IsStartupScriptRegistered("alert")) Then
                    Page.ClientScript.RegisterStartupScript _
                    (Me.GetType(), "alert", "ToggleDiv('second');", True)
                End If
            ElseIf ctrlname = "ctl00$ContentPlaceHolder1$gvPermissions" Then
                If (Not ClientScript.IsStartupScriptRegistered("alert")) Then
                    Page.ClientScript.RegisterStartupScript _
                    (Me.GetType(), "alert", "ToggleDiv('third');", True)
                End If
            ElseIf ctrlname = "ctl00$ContentPlaceHolder1$gvComments" Then
                If (Not ClientScript.IsStartupScriptRegistered("alert")) Then
                    Page.ClientScript.RegisterStartupScript _
                    (Me.GetType(), "alert", "ToggleDiv('fourth');", True)
                End If
            Else
                If (Not ClientScript.IsStartupScriptRegistered("alert")) Then
                    Page.ClientScript.RegisterStartupScript _
                    (Me.GetType(), "alert", "ToggleDiv('fifth');", True)
                    Label1.Visible = True
                    Label1.Text = "Update successful"
                End If

                'Dim myscript As String = "ToggleDiv('first')"
                'RegisterStartupScript("Startup", scriptString)
                'Page.ClientScript.RegisterStartupScript(typeof(Page)is, "key", myScript, true)
                'ScriptManager.RegisterStartupScript(typeof(Page)is, "key", myScript, true)
                'ElseIf ctrlname = "ctl00$ContentPlaceHolder1$GridView4" Then
                'Dim myscript2 As String = "ToggleDiv('Second')"
            End If
        End If
        Dim conn = New OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ToString())

        Dim ID_string As String = " SELECT [UserID] FROM aspnet_Users WHERE UserName = '" & User.Identity.Name & "' "
        Dim findIDCmd1 As New OleDbCommand(ID_string, conn)
        conn.Open()
        Dim ID1 As OleDbDataReader = findIDCmd1.ExecuteReader
        ID1.Read()
        Dim UserID As Integer = ID1("UserID")
        Session("UserID") = UserID

        Dim mem As String

        Dim Details_string As String = " SELECT [MembershipID_FK] FROM Userdetails WHERE UserID_FK = " & UserID & " "
        Dim Details_command As OleDb.OleDbCommand = New OleDb.OleDbCommand(Details_string, conn)
        Dim Det_reader As OleDb.OleDbDataReader = Details_command.ExecuteReader()
        If Det_reader.HasRows Then
            While Det_reader.Read()
                mem = Det_reader.Item(0).ToString()
            End While
            If mem = "4" Or mem = "3" Then

                btn.Enabled = True
                Button1.Enabled = True
                Button2.Enabled = True
                Button3.Enabled = True

            End If
        End If

    End Sub

End Class